// pages/my/Zx/Zx1/Zx1.js

const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url: '',
    activeTab: 'completed',
    completedList: [],
    uncompletedList: [],
    show1: false,
    markText: '',
    value: 3,
    aid: '',
    cid: ''
  },
  // 用户评价
  userMark(e){
    let value = e.detail.value;
    this.setData({
      markText: value
    })
  },
  // 评分变化
  onChange(e){
    this.setData({
      value: e.detail
    })
  },
  //展示弹出层
  showPop(e){
    let status = e.currentTarget.dataset.status;
    let aid = e.currentTarget.dataset.aid;
    let cid = e.currentTarget.dataset.cid;
    if(status!=3){
      this.setData({
        show1: true,
        aid: aid,
        cid: cid
      });
    }
  },
  //关闭弹出层(完成评价)
  onClose(){
    this.setData({
      show1: false,
    });
    let that = this;
    wx.request({
      url: that.data.url+'usermark/add',
      method: 'POST',
      data:{
        consultId: that.data.cid,
        userId: wx.getStorageSync('user').id,
        appId: that.data.aid,
        marktext: that.data.markText,
        markstar: that.data.value,
      },
      success(resp){
        that.updateStatus();
      }
    })
  },
  // 修改状态值
  updateStatus(){
    let that = this;
    wx.request({
      url: that.data.url+'appointment/update',
      method: 'PUT',
      data:{
        id: that.data.aid,
        status: 3
      },
      success(resp){
        console.log(resp);
        that.getComplete();
      }
    })
  },
  //根据status不为0时获取的咨询预约表（已完成）
  getComplete(){
    console.log(666);
    let that = this;
    wx.request({
      url: that.data.url+'appointment/selectByStatus',
      method: 'POST',
      data: {
        userId: wx.getStorageSync('user').id,
        statusList: [1,2,3]
      },
      success(resp){
        let result = resp.data;
        // console.log(result.data);
        that.setData({
          completedList: result.data
        })
      }
    })
  },
  //根据status不为0时获取的咨询预约表（未完成）
  getUncomplete(){
    let that = this;
    wx.request({
      url: that.data.url+'appointment/selectByStatus',
      method: 'POST',
      data: {
        userId: wx.getStorageSync('user').id,
        statusList: [0]
      },
      success(resp){
        let result = resp.data;
        console.log(result.data);
        that.setData({
          uncompletedList: result.data
        })
      }
    })
  },
  // 删除预约
  onCancel(e){
    let aid = e.currentTarget.dataset.aid;
    let that = this;
    console.log(aid);
    wx.request({
      url: that.data.url+'appointment/deletewc',
      method: 'GET',
      data:{
        id: aid
      },
      success(resp){
        console.log(666);
        that.getUncomplete()
      }
    })
  },
  switchTab1: function (e) {
    this.setData({
      activeTab: e.currentTarget.dataset.tab
    });
    this.getComplete();
  },
  switchTab2: function (e) {
    this.setData({
      activeTab: e.currentTarget.dataset.tab
    });
    this.getUncomplete();
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      url: app.globalData.URL,
    });
    this.getComplete();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})